<template>
  <div>
    <el-dialog
      @close="cancel"
      :title="formtype == 1 ? '新增节假日' : '编辑节假日'"
      class="holiday_dialog"
      width="460px"
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="form" :rules="rules" ref="ruleForm" label-position="left">
        <el-form-item
          label="节假日名称"
          prop="Name"
          :label-width="formLabelWidth"
        >
          <el-input
            class="input_border_bottom"
            v-model="form.Name"
            placeholder="请输入名称"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item
          label="数据来源"
          prop="Resoures"
          :label-width="formLabelWidth"
        >
          <el-select
            class="select_border_bottom"
            v-model="form.Resoures"
            placeholder="数据来源"
          >
            <el-option label="手工登记" value="1"></el-option>
            <el-option label="网络同步" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型" prop="Type" :label-width="formLabelWidth">
          <el-select
            class="select_border_bottom"
            v-model="form.Type"
            placeholder="请选择类型"
          >
            <el-option label="每年固定" value="1"></el-option>
            <el-option label="每年变化" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="年度" v-if="form.Type =='2'" prop="Year" :label-width="formLabelWidth">
          <el-date-picker
            v-model="form.Year"
            align="right"
            class="date_picker_defin"
            value-format="yyyy"
            type="year"
            placeholder="选择年"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item
          label="开始结束日期"
          prop="StartDate"
          label-width="120px"
        >
          <el-date-picker
            v-model="value6"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            type="daterange"
            class="time_picker_defin"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="描述" prop="Desc" :label-width="formLabelWidth">
          <el-input
            class="textarea_border_bottom"
            v-model="form.Desc"
            type="textarea"
            placeholder="请输入描述"
            auto-complete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="commit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
var that
export default {
  data() {
    return {
      dialogFormVisible: false,
      formtype: 1,
      formLabelWidth: '100px',
      value6: [],
       rules: {
          Name: [
            { required: true, message: '请输入名称', trigger: 'blur' },
          ],
          Resoures: [
            { required: true, message: '请选择来源', trigger: 'blur' },
          ],
          Type: [
            { required: true, message: '请选择类型', trigger: 'blur' },
          ],
          StartDate: [
            { required: true, message: '请选择时间', trigger: 'blur' },
          ],
          Year: [
            { required: true, message: '请选择年', trigger: 'blur' },
          ],
          },
      form: {
        Name: '',
        Resoures: '1',
        Type: '1',
        StartDate: '',
        EndDate: '',
        Desc: '',
      }
    }
  },
  created() {
    that = this
  },
  watch: {
    "$store.state.Humanmanage.SaveHoliday": function (data) {
      this.$message({
            type: 'success',
            message: '操作成功!'
          });
          this.cancel();
          this.$parent.getlistdata();
    },
    'value6': (e) => {
      that.form.StartDate = e[0];
      that.form.EndDate = e[1];
    }
  },
  methods: {

    commit() {
      this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            let obj = {
              "MN": "SaveHoliday",
              "RequestId": 1,
              "UserId": 1,
              "DataContent": this.form
            }
            this.MIX_send(obj);
          } else {
            return false;
          }
        });
    },
    cancel() {
      this.form= {
        Name: '',
        Resoures: '1',
        Type: '1',
        StartDate: '',
        EndDate: '',
        Desc: '',
      }
      this.dialogFormVisible = false;
    }
  },
}
</script>

<style lang="less" scoped>
</style>